package com.hqyj.utile;

import com.hqyj.dao.ReserveMapper;
import com.hqyj.dao.SysTableMapper;
import com.hqyj.pojo.Goods;
import com.hqyj.pojo.Reserve;
import com.hqyj.pojo.SysTable;

import java.text.SimpleDateFormat;
import java.util.List;

//思考
public class ColorUtil {
//    去遍历table表，根据状态，来设置table的背景，设置属性值
    public static List<SysTable> updateTableColor(List<SysTable> list){

        for (SysTable sysTable: list) {
            if (sysTable.gettState().equals("可预定")){
                sysTable.setColName("class=success");

            }else if (sysTable.gettState().equals("可抢座")){
                sysTable.setColName("class=warning");

            }else if (sysTable.gettState().equals("已占座")){
                sysTable.setColName("class=danger");
                sysTable.setButonUser1("disabled");
            }
        }
        return list;




    }


    //获得这个值后要减一，再去判断是否为“0”，是0就改为“可预定”否则为“可抢座”
    public static void updateTableState(List<Reserve> listReserve, SysTableMapper sysTableMapper, ReserveMapper reserveMapper, Reserve reserve) {

            int count = reserveMapper.countNumberBytId(reserve.gettId());
            if((count-1)==0){
                //设置此桌位的State的值
                sysTableMapper.updateTableState(reserve.gettId());
            }
    }

    public static List<Goods> updateReviewTableColor(List<Goods> list) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (Goods reserve: list) {
            String timeFormat = sdf.format(reserve.getgSaleTime());
            reserve.setStringDate(timeFormat);
            System.out.println("时间为："+ timeFormat);
            if (reserve.getField()==1){
                System.out.println("我想获取你的reviewstate"+reserve);
                reserve.setColName("class=active");

            }else if (reserve.getField()==2||reserve.getField()==4){
                reserve.setColName("class=success");

            }else if (reserve.getField()==3){
                reserve.setColName("class=danger");
            }
        }
        return list;
    }

    public static List<Goods> updateReserveColor1(List<Goods> list) {
        for (Goods reserve: list) {
            if (reserve.getField()==2){
                System.out.println("我想获取你的reviewstate"+reserve);
                reserve.setColName("class=success");

            }else if (reserve.getField()==1){
                reserve.setButonUser1("disabled");
                reserve.setColName("class=active");

            }else if (reserve.getField()==3){
                reserve.setButonUser1("disabled");
                reserve.setButonUser2("disabled");
                reserve.setButonUser4("disabled");
                reserve.setColName("class=danger");
            }else if (reserve.getReviewState()==4){
                reserve.setColName("class=warning");
                reserve.setButonUser1("disabled");
                reserve.setButonUser2("disabled");
                reserve.setButonUser4("disabled");
            }
        }
        return list;
    }
}
